package com.flyduck.common.vo;

import com.flyduck.common.exception.CommonExceptionCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @program: flyduck-platform
 * @description: 返回结果封装
 * @author: flyduck
 * @create: 2021-01-02 18:50
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    private Integer code;
    private String message;
    private T data;

    //返回成功
    public static Result success(){
        return new Result(CommonExceptionCode.SUCCESS.getCode(),null,null);
    }

    public static Result success(String message){
        return new Result(CommonExceptionCode.SUCCESS.getCode(),message,null);
    }

    //返回成功
    public static <T> Result<T> success(T data){
        return new Result(CommonExceptionCode.SUCCESS.getCode(),null,data);
    }

    //返回成功
    public static <T> Result<T> success(T data,String message){
        return new Result(CommonExceptionCode.SUCCESS.getCode(),message,data);
    }


    //返回失败
    public static Result failure(Integer code,String message){
        return new Result(code,message,null);
    }

}
